#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_beep.h"
#include "bsp_epit.h"
#include "bsp_gpt.h"
#include "bsp_lcd.h"
#include "stdio.h"
#include "bsp_rtc.h"
#include "bsp_ap3216c.h"

static void gpt_handler(uint32_t nirq, void *args)
{
    static int led_status = OFF;
    if (GPT2->SR & 1)
    {
        led_switch(0, led_status);
        led_status = !led_status;
    }
    GPT2->SR |= 1 << 0;
}

void test_main_i2c()
{
    led_init();
    beep_init();
    gpt_init(GPT2, 0, 66000000 / 5);
    gpt_irq_init(GPT2, GPT2_IRQn, gpt_handler, NULL);
    beep_switch(ON);
    delay(500);
    beep_switch(OFF);
    lcd_init();
    printf("i2c test \n");
    ap3216_init();
    uint32_t colors[] = {
        LCD_WHITE, LCD_YELLOW, LCD_GRAY, LCD_RED, LCD_GREEN, LCD_BLUE};
    int ncolor = sizeof(colors) / sizeof(*colors);
    int icolor = 0;
    while (1)
    {
        icolor++;
        icolor %= ncolor;
        lcd_clear(colors[icolor]);
        // 可以有更多复杂的操作
        lcd_next_buff();
        delayms(500);
    }
}